package com.control.qct.businesssteward.activity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.control.qct.businesssteward.R;
import com.control.qct.businesssteward.base.BaseActivity;
import com.control.qct.businesssteward.base.BaseBean;
import com.control.qct.businesssteward.httputils.HttpUtils;
import com.control.qct.businesssteward.utils.ActivityCollector;
import com.control.qct.businesssteward.utils.CacheUtils;
import com.control.qct.businesssteward.utils.DialogUtil;
import com.control.qct.businesssteward.utils.SPUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SettingActivity extends BaseActivity implements HttpUtils.IHttpResult {
    @BindView(R.id.tv_clear_cache)
    TextView mTvClearCache;
    @BindView(R.id.rl_clear_cache)
    RelativeLayout mRlClearCache;
    @BindView(R.id.tv_exit_login)
    TextView mTvExitLogin;

    public SettingActivity() {
        super(R.layout.activity_setting);
    }

    @Override
    protected void initView() {
        setLeftIcon(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        setTitle("设置");
        mTvClearCache.setText(CacheUtils.getTotalCacheSize(this));
    }


    @OnClick({R.id.rl_clear_cache, R.id.tv_exit_login})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_clear_cache:
                DialogUtil.getAlertDialog(this, "提示", "是否清理缓存？", "确定", "取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        CacheUtils.clearAllCache(SettingActivity.this);
                        mTvClearCache.setText(CacheUtils.getTotalCacheSize(SettingActivity.this));
                        dialogInterface.dismiss();
                    }
                }).show();
                break;
            case R.id.tv_exit_login:
                DialogUtil.getAlertDialog(this, "提示", "是否退出应用？", "确定", "取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        mNetProtocol.exits(SettingActivity.this, SettingActivity.this);
                        dialogInterface.dismiss();
                    }
                }).show();
                break;
        }
    }

    @Override
    public void onSuccess(BaseBean baseBean) {
        ActivityCollector.finishAll();
        startActivity(LoginActivity.class);
    }

    @Override
    public void onFail(BaseBean baseBean) {
        showShortToast(baseBean.getMessage());
    }
}
